<include file="Public/header" />
<body onselectstart="return false">
<div class="main">
    <div class="content">
        <div class="head-content">
            <div class="head-title">角色列表</div>
            <div class="head-search">
                <a href="<{:U('add')}>" class="form-button color-bg-yellow" >添加</a>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="head-content">
            <form action="<{:U('User/index')}>" method='get'>
                <div class="head-search">
                    <input class="form-input-small" type="text" value="<{:I('get.title')}>" name='title' placeholder="角色名" />
                    <button class="form-button color-bg-green">搜索</button>
                </div>
            </form>
        </div>
    </div>
    <div class="table-list">
        <table cellpadding="0" cellspacing="0">
            <thead>
            <tr>
                <th>角色名</th>
                <th>角色状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <foreach name='list' item='vo'>
                <tr>
                    <td><{$vo['title']}></td>
                    <td><{$vo['status']|get_group_status}></td>
                    <td>
                        <div class="operate-list">
                            <button style="float: none" onclick="show(<{$vo['id']}>)"  class="form-button color-bg-green">分配权限</button>
                            <a class="heart" title='修改' href="<{:U('edit',array('id'=>$vo['id']))}>">
                                <i class="iconfont">&#xe64f;</i>
                            </a>
                            <a class="delete" title='删除' onclick="info(<{$vo['id']}>)" href="javascript:void(0)">
                                <i class="iconfont">&#xe62b;</i>
                            </a>
                        </div>
                    </td>
                </tr>
            </foreach>
        </table>

        <!--没有结果时显示-->
        <if condition="!$list" >
            <div class="nodata"><i class="iconfont">&#xe607;</i><span>没有查询到符合条件的记录</span></div>
        </if>

        <!--分页效果-->
        <div class="table-foot">
            <div class="foot-page">
                <ul><{$page}></ul>
            </div>
        </div>

    </div>
</div>

<!--提示框-->
<div class="pop-window pop-delete" id="info">
    <input type="hidden" name="id" id="id"   >
    <div class="pop-notice FromUpToDown">
        <div class="notice-head">
            <div class="notice-head-title">温馨提示</div>
            <div class="notice-head-delete">×</div>
        </div>
        <div class="notice-content">
            <div>
                <i class="iconfont">&#xe607;</i>
            </div>
            <div class="notice-content-word">是否要删除本条信息？</div>
        </div>
        <div class="notice-foot">
            <a href="javascript:;" onclick="del()" class="notice-btn btn-submit">确定</a>
            <a href="javascript:;" class="notice-btn btn-drop">取消</a>
        </div>
    </div>
</div>

<!--权限选择-->
<div class="pop-window pop-delete" id="right">
    <input type="hidden" name="user_id" >
    <div class="pop-notice FromUpToDown">
        <div class="notice-head">
            <div class="notice-head-title">分配权限</div>
            <div class="notice-head-delete">×</div>
        </div>
        <div class="notice-content" id="rule_list">

        </div>
        <div class="notice-foot">
            <a href="javascript:;" onclick="saveRight()" class="notice-btn btn-submit">确定</a>
            <a href="javascript:;" class="notice-btn btn-drop">取消</a>
        </div>
    </div>
</div>


<include file="Public/footer" />

<script>
    //弹出询问框
    function info(id){
        $("#id").val(id);
        $("#info").show();
    }

    //删除
    function del(){
        $('#info').hide();
        var id = $("#id").val();
        $.get(
                "<{:U('del')}>",
                {
                    id:id
                },
                function(res){
                    if(res.status == false){
                        layer.msg(res.info,{time:1000});
                    }else{
                        layer.msg(res.info,{time:1000});
                        setTimeout("location.reload()",1000);
                    }
                }
        );
    }
</script>
<script>
    function show(id)
    {
        $("input[name='user_id']").val(id);
        $.get(
                "<{:U('getRule')}>",
                {
                   id:id
                },
                function(res){
                    $("#rule_list").html(res);
                    $("#right").show();
                }
        );
    }

    function saveRight()
    {
        var rules = [];
        $("input:checkbox:checked").each(function () {
            rules.push($(this).val());
        });
        $.post(
                "<{:U('saveRight')}>",
                {
                  user_id:$("input[name='user_id']").val(),
                  rules:rules
                },function(res){
                    $("#right").hide();
                    layer.msg(res.info,{time:1000});
                }
        )
    }


</script>

</body>
</html>